.class public Lorg/microemu/cldc/file/FileSystemConnectorImpl;
.super Lorg/microemu/microedition/io/ConnectorAdapter;
.source "FileSystemConnectorImpl.java"

# interfaces
.implements Lorg/microemu/microedition/ImplementationUnloadable;


# static fields
.field public static final PROTOCOL:Ljava/lang/String; = "file://"


# instance fields
.field private acc:Ljava/security/AccessControlContext;

.field private fsRoot:Ljava/lang/String;

.field private openConnection:Ljava/util/List;


# direct methods
.method constructor <init>(Ljava/lang/String;)V
    .locals 1
    .parameter "fsRoot"

    .prologue
    .line 58
    invoke-direct {p0}, Lorg/microemu/microedition/io/ConnectorAdapter;-><init>()V

    .line 56
    new-instance v0, Ljava/util/Vector;

    invoke-direct {v0}, Ljava/util/Vector;-><init>()V

    iput-object v0, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->openConnection:Ljava/util/List;

    .line 59
    invoke-static {}, Ljava/security/AccessController;->getContext()Ljava/security/AccessControlContext;

    move-result-object v0

    iput-object v0, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->acc:Ljava/security/AccessControlContext;

    .line 60
    iput-object p1, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->fsRoot:Ljava/lang/String;

    .line 61
    return-void
.end method

.method static access$000(Lorg/microemu/cldc/file/FileSystemConnectorImpl;)Ljava/lang/String;
    .locals 1
    .parameter "x0"

    .prologue
    .line 47
    iget-object v0, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->fsRoot:Ljava/lang/String;

    return-object v0
.end method

.method static doPrivilegedIO(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    .locals 3
    .parameter "action"
    .parameter "context"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 81
    :try_start_0
    invoke-static {p0, p1}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    return-object v1

    .line 82
    :catch_0
    move-exception v0

    .line 83
    .local v0, e:Ljava/security/PrivilegedActionException;
    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object v1

    instance-of v1, v1, Ljava/io/IOException;

    if-eqz v1, :cond_0

    .line 84
    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/io/IOException;

    throw p0

    .line 86
    .restart local p0
    :cond_0
    new-instance v1, Ljava/io/IOException;

    invoke-virtual {v0}, Ljava/security/PrivilegedActionException;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v1
.end method


# virtual methods
.method notifyClosed(Lorg/microemu/cldc/file/FileSystemFileConnection;)V
    .locals 1
    .parameter "con"

    .prologue
    .line 106
    iget-object v0, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->openConnection:Ljava/util/List;

    invoke-interface {v0, p1}, Ljava/util/List;->remove(Ljava/lang/Object;)Z

    .line 107
    return-void
.end method

.method notifyMIDletDestroyed()V
    .locals 2

    .prologue
    .line 91
    iget-object v0, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->openConnection:Ljava/util/List;

    invoke-interface {v0}, Ljava/util/List;->size()I

    move-result v0

    if-lez v0, :cond_0

    .line 92
    new-instance v0, Ljava/lang/StringBuffer;

    invoke-direct {v0}, Ljava/lang/StringBuffer;-><init>()V

    const-string v1, "Still has "

    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v0

    iget-object v1, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->openConnection:Ljava/util/List;

    invoke-interface {v1}, Ljava/util/List;->size()I

    move-result v1

    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(I)Ljava/lang/StringBuffer;

    move-result-object v0

    const-string v1, " open file connections"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Lorg/microemu/log/Logger;->warn(Ljava/lang/String;)V

    .line 94
    :cond_0
    return-void
.end method

.method public open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
    .locals 4
    .parameter "name"
    .parameter "mode"
    .parameter "timeouts"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 65
    const-string v1, "file://"

    invoke-virtual {p1, v1}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_0

    .line 66
    new-instance v1, Ljava/io/IOException;

    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    const-string v3, "Invalid Protocol "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 69
    :cond_0
    new-instance v1, Lorg/microemu/cldc/file/FileSystemConnectorImpl$1;

    invoke-direct {v1, p0, p1}, Lorg/microemu/cldc/file/FileSystemConnectorImpl$1;-><init>(Lorg/microemu/cldc/file/FileSystemConnectorImpl;Ljava/lang/String;)V

    iget-object v2, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->acc:Ljava/security/AccessControlContext;

    invoke-static {v1, v2}, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->doPrivilegedIO(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Ljavax/microedition/io/Connection;

    .line 75
    .local v0, con:Ljavax/microedition/io/Connection;
    iget-object v1, p0, Lorg/microemu/cldc/file/FileSystemConnectorImpl;->openConnection:Ljava/util/List;

    invoke-interface {v1, v0}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 76
    return-object v0
.end method

.method public unregisterImplementation()V
    .locals 0

    .prologue
    .line 102
    invoke-static {p0}, Lorg/microemu/cldc/file/FileSystem;->unregisterImplementation(Lorg/microemu/cldc/file/FileSystemConnectorImpl;)V

    .line 103
    return-void
.end method
